
Partial Class WebForm_ManageTrainingTeacher_AddTrainingTeacherl
    Inherits System.Web.UI.UserControl
    
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.fv.InsertItemTemplate = Me.fv.ItemTemplate
        Me.fv.EditItemTemplate = Me.fv.ItemTemplate
    End Sub

    Protected Sub fv_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles fv.DataBound

    End Sub

    Protected Sub fv_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles fv.ItemCommand
        If e.CommandName = "btnSave" Then
            If Me.SaveData() = True Then
                RaiseEvent Saved(Me, New EventArgs)
            End If
        End If
    End Sub
End Class

Partial Class WebForm_ManageTrainingTeacher_AddTrainingTeacherl
    Public Sub InitData()
        Me.fv.ChangeMode(FormViewMode.Insert)
        'TryCast(fv.FindControl("txtParent"), TextBox).Text = Me.DefaultParentID
    End Sub

    Public Sub InitData(ByVal teacherID As String)
        Me.fv.ChangeMode(FormViewMode.Edit)
        Me.TeacherID = teacherID
        Me.BindData()
        'TryCast(fv.FindControl("txtTeacherID"), TextBox).Enabled = False
        'TryCast(fv.FindControl("txtParent"), TextBox).Enabled = False
    End Sub

    Private Sub BindData()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select t.* ")
        sql.AppendFormat(" from TrainingTeacher t ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and t.TeacherID = '{0}' ", Me.TeacherID)

        dt = dat.GetData(sql)

        Me.fv.DataSource = dt
        Me.fv.DataBind()
    End Sub


    Private Function SaveData() As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        Using scope As New Transactions.TransactionScope
            If Me.fv.CurrentMode = FormViewMode.Insert Then
                sql.Length = 0
                sql.AppendFormat("insert TrainingTeacher (TeacherName,MobilePhone,OtherPhone,Address,Description) select ")
                sql.AppendFormat("'{0}' ", TryCast(fv.FindControl("txtTeacherName"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("txtMobilePhone"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("txtOtherPhone"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("txtAddress"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("txtDescription"), TextBox).Text)

                dat.AccData(sql)
                Me.TeacherName = TryCast(fv.FindControl("txtTeacherName"), TextBox).Text

            ElseIf Me.fv.CurrentMode = FormViewMode.Edit Then
                sql.Length = 0
                sql.AppendFormat("update TrainingTeacher set ")
                sql.AppendFormat(" TeacherName='{0}' ", TryCast(fv.FindControl("txtTeacherName"), TextBox).Text)
                sql.AppendFormat(",MobilePhone='{0}' ", TryCast(fv.FindControl("txtMobilePhone"), TextBox).Text)
                sql.AppendFormat(",OtherPhone='{0}' ", TryCast(fv.FindControl("txtOtherPhone"), TextBox).Text)
                sql.AppendFormat(",Address='{0}' ", TryCast(fv.FindControl("txtAddress"), TextBox).Text)
                sql.AppendFormat(",Description='{0}' ", TryCast(fv.FindControl("txtDescription"), TextBox).Text)
                sql.AppendFormat("where TeacherID = '{0}' ", Me.TeacherID)
                dat.AccData(sql)
                Me.TeacherName = TryCast(FV.FindControl("txtTeacherName"), TextBox).Text
            End If

            scope.Complete()
        End Using

        Return True
    End Function

    Public Property TeacherID() As String
        Get
            Return ViewState("SelectedTeacherID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedTeacherID") = value
        End Set
    End Property
    Public Property TeacherName() As String
        Get
            Return ViewState("SelectedTeacherName")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedTeacherName") = value
        End Set
    End Property


    Public Event Saved(ByVal source As Object, ByVal e As EventArgs)
End Class
